package smartcampus.scjava.controller.second;

import com.qiniu.util.Auth;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import smartcampus.scjava.custom.ResultVO;
import smartcampus.scjava.utils.HttpUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 北煜
 */
@Api(tags = "人脸识别")
@Slf4j
@RestController
@RequestMapping("/Face")
public class FaceController {

    @GetMapping("/FaceVideo")
    @ApiOperation(value = "人脸识别视频")
    public ResultVO<String> faceVideo() {
        String Url = "http://127.0.0.1:5000/video";
        return ResultVO.success(HttpUtil.sendGet(Url, 60000));
    }

    @GetMapping("/FaceImage")
    @ApiOperation("人脸识别图片")
    public ResultVO<String> faceImage( String filePath ) {
        System.out.println(filePath);
        String url = "http://127.0.0.1:5000/SaveFace";
        Map<String, String> params = new HashMap<>();
        params.put("filePath", filePath);
        System.out.println(HttpUtil.sendPost(url, params,60000));
        return ResultVO.success("1");
    }

    @GetMapping("/FaceUpload")
    @ApiOperation("人脸识别图片上传")
    public ResultVO<?> faceUpload() {
        String access_key = "CKAWgGNUtJB1TFofmKtQ9nqfvqDS6lQdKkAiHh04";
        String secret_key = "ttBa1dX8s9aoYbzqjGf6Sn63ErZYikWo1ELHsbuQ";
        String bucket_name = "linter-beiyu";

        Auth auth = Auth.create(access_key, secret_key);
        String upToken = auth.uploadToken(bucket_name);
        System.out.println(upToken);
        return ResultVO.success(upToken);
    }

    @GetMapping("/FaceBattle")
    @ApiOperation("人脸识别对比")
    public ResultVO<?> faceBattle(){
        String face_token1 = "";
        String face_token2 = "";
        String url = "http://127.0.0.1:5000/FaceBattle";
        Map<String, String> params = new HashMap<>();
        params.put("face_token1", face_token1);
        params.put("face_token2", face_token2);
        return ResultVO.success(HttpUtil.sendPost(url, params, 60000));
    }
}
